package com.zmn.plat.services.impl.channel.tariff;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.zmn.plat.model.entity.channel.ChannelFaultPriceVO;
import com.zmn.plat.model.entity.channel.tariff.ChannelTariff;
import com.zmn.plat.model.entity.channel.tariff.ChannelTariffQuery;
import com.zmn.plat.model.vo.channel.tariff.ChannelTariffVo;
import com.zmn.plat.model.vo.product.tariff.item.price.ProductServiceItemExcutePriceQueryVo;
import com.zmn.plat.model.vo.service.tariff.ChannelServiceTariffVO;
import com.zmn.plat.persistence.interfaces.channel.tariff.ChannelTariffDao;
import com.zmn.plat.services.interfaces.channel.tariff.ChannelTariffService;

@Service
public class ChannelTariffServiceImpl implements ChannelTariffService {

    @Resource
    ChannelTariffDao channelTariffDao;

    @Override
    public ChannelTariff findByKey(Integer relateId) {
        return channelTariffDao.findByKey(relateId);
    }

    @Override
    public ChannelFaultPriceVO findByChannelIdAndBizTypeAndTariffType(Integer channelId, Integer bizType, Integer tariffType) {
        return channelTariffDao.findByChannelIdAndBizTypeAndTariffType(channelId, bizType, tariffType);
    }

    @Override
    public List<ChannelFaultPriceVO> listByChannelId(Integer channelId) {
        return channelTariffDao.listByChannelId(channelId);
    }

    @Override
    public List<ChannelTariffVo> listPageByQuery(ChannelTariffQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return channelTariffDao.listPageByQuery(query);
    }

    @Override
    public List<ChannelTariffVo> listAjaxPageByQuery(ChannelTariffQuery query) {
        int count = countAjaxByQuery(query);
        query.setTotalCount(count);
        return channelTariffDao.listAjaxPageByQuery(query);
    }

    @Override
    public List<ChannelTariff> listByQuery(ChannelTariffQuery query) {
        return channelTariffDao.listByQuery(query);
    }

    @Override
    public List<ChannelTariff> listAll() {
        return channelTariffDao.listAll();
    }

    @Override
    public List<ChannelServiceTariffVO> listProductTariffRelationByQuery(ProductServiceItemExcutePriceQueryVo query) {
        return channelTariffDao.listProductTariffRelationByQuery(query);
    }

    @Override
    @Cacheable(cacheNames = "redis1h", key = "'price:findFaultTariffByChannelId:channelId:'+#p0+':bizType:'+#p1+':tariffType:'+#p2")
    public ChannelServiceTariffVO findFaultTariffByChannelId(Integer channelId, Integer keepType, Integer tariffType) {
        return channelTariffDao.findFaultTariffByChannelId(channelId, keepType, tariffType);
    }

    @Override
    public Integer countByQuery(ChannelTariffQuery query) {
        return channelTariffDao.countByQuery(query);
    }

    @Override
    public Integer countAjaxByQuery(ChannelTariffQuery query) {
        return channelTariffDao.countAjaxByQuery(query);
    }

    @Override
    public Integer updateByKey(ChannelTariff channelTariff) {
        return channelTariffDao.updateByKey(channelTariff);
    }

    @Override
    public Integer insert(ChannelTariff channelTariff) {
        return channelTariffDao.insert(channelTariff);
    }

    @Override
    public Integer insertBatch(List<ChannelTariff> channelTariffs) {
        return channelTariffDao.insertBatch(channelTariffs);
    }

    @Override
    public Integer deleteByKey(Integer relateId) {
        return channelTariffDao.deleteByKey(relateId);
    }

    @Override
    public Integer deleteByKeys(List<String> ids) {
        return channelTariffDao.deleteByKeys(ids);
    }

    @Override
    public Integer deleteByTariffIdAndChannelIds(List<String> ids, Integer tariffId) {
        return channelTariffDao.deleteByTariffIdAndChannelIds(ids, tariffId);
    }

    @Override
    public Integer deleteByChannelIdsAndBizTypeAndTariffType(List<String> ids, Integer bizType, Integer tariffType) {
        return channelTariffDao.deleteByChannelIdsAndBizTypeAndTariffType(ids, bizType, tariffType);
    }

    @Override
    public void copy(Integer originalChannelId, int targetChannelId, String operator) {

        channelTariffDao.copy(originalChannelId, targetChannelId, operator);
    }
}